using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class BillOutMap : EntityTypeConfiguration<BillOut>
    {
        public BillOutMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .HasMaxLength(20);

            this.Property(t => t.Description)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("BillOuts");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.OrderID).HasColumnName("OrderID");
            this.Property(t => t.User1ID).HasColumnName("User1ID");
            this.Property(t => t.User2ID).HasColumnName("User2ID");
            this.Property(t => t.Date1).HasColumnName("Date1");
            this.Property(t => t.Date2).HasColumnName("Date2");
            this.Property(t => t.TotalMoney).HasColumnName("TotalMoney");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.WarehouseID).HasColumnName("WarehouseID");

            // Relationships
            this.HasOptional(t => t.Order)
                .WithMany(t => t.BillOuts)
                .HasForeignKey(d => d.OrderID);
            this.HasOptional(t => t.Employee)
                .WithMany(t => t.BillOuts)
                .HasForeignKey(d => d.User1ID);
            this.HasOptional(t => t.Employee1)
                .WithMany(t => t.BillOuts1)
                .HasForeignKey(d => d.User2ID);
            this.HasOptional(t => t.Stock)
                .WithMany(t => t.BillOuts)
                .HasForeignKey(d => d.WarehouseID);

        }
    }
}
